var t = getApp(), a = require("../../../../utils/cityList.js");

Page({
    data: {
        provinceArray: [ "北京市" ],
        cityArray: [ "北京" ],
        areaArray: [ "东城区" ],
        citySelectIndex: [ 0, 0, 0 ],
        province: "北京",
        city: "市区",
        area: "东城区",
        backResult: 0
    },
    onLoad: function(t) {
        var e = t.backResult, n = a.cityList.provinces.map(function(t, a, e) {
            return t.name;
        }), i = a.cityList.provinces[0].citys.map(function(t, a, e) {
            return t.name;
        }), c = a.cityList.provinces[0].citys[0].countys.map(function(t, a, e) {
            return t;
        });
        this.setData({
            provinceArray: n,
            cityArray: i,
            areaArray: c,
            backResult: e
        });
    },
    bindMultiPickerChange: function(t) {
        var e = t.detail.value, n = this.data.citySelectIndex;
        e[0] != n[0] ? (e[1] = 0, e[2] = 0) : e[1] != n[1] && (e[2] = 0), console.log(e);
        var i = a.cityList.provinces[e[0]].citys.map(function(t, a, e) {
            return t.name;
        }), c = a.cityList.provinces[e[0]].citys[e[1]].countys.map(function(t, a, e) {
            return t;
        });
        e[0] != n[0] ? (n = [ e[0], 0, 0 ], console.log("改变省")) : e[1] != n[1] ? (n = [ e[0], e[1], 0 ], 
        console.log("改变市")) : e[2] != n[2] && (n = [ e[0], e[1], e[2] ], console.log("改变区"));
        var o = this.data.provinceArray[e[0]], r = i[e[1]], s = c[e[2]];
        this.setData({
            cityArray: i,
            areaArray: c,
            citySelectIndex: n,
            province: o,
            city: r,
            area: s
        });
    },
    clickOk: function(a) {
        var e = this.data.province, n = this.data.city, i = this.data.area;
        if (console.log(e + n + i), 1 == this.data.backResult) {
            var c = getCurrentPages();
            c[c.length - 2].setData({
                province: e,
                city: n,
                area: i
            }), wx.navigateBack({});
        } else {
            t.network.post({
                url: t.url.editInfo,
                params: {
                    province: e,
                    city: n,
                    county: i
                },
                before: function() {
                    wx.showLoading({
                        title: "修改中"
                    });
                },
                success: function(a) {
                    if (wx.hideLoading(), 1 == a.data.result) {
                        t.util.showToast(a.data.message);
                        var e = getCurrentPages();
                        e[e.length - 2].setData({
                            needUpdate: !0
                        }), setTimeout(function() {
                            wx.navigateBack({});
                        }, 1e3);
                    }
                },
                fail: function() {
                    wx.hideLoading(), t.util.showToast("修改失败，请重试");
                },
                complete: function() {}
            });
        }
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {}
});